﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Threading;

namespace WPF_Binding1
{
    /// <summary>
    /// Window1.xaml에 대한 상호 작용 논리
    /// </summary>
    public partial class Window1 : Window
    {
        int idx = 0;
        List<Data> strlist = new List<Data>();
        public Window1()
        {
            InitializeComponent();
        }

        private void listBox1_Loaded(object sender, RoutedEventArgs e)
        {
            listBox1.ItemsSource = strlist;
            strlist.Clear();
            for (int i = 0; i < 600; i++)
            {
                if (idx == 65535)
                {
                    idx = 0;
                }
                Data AddItem = new Data();
                AddItem.name = (idx++).ToString();
                strlist.Add(AddItem);
            }

            listBox1.Items.Refresh();

            Thread th1 = new Thread(new ThreadStart(() =>
            {
                while (true)
                {
                    strlist.Clear();
                    for (int i = 0; i < 600; i++)
                    {
                        if (idx == 65535)
                        {
                            idx = 0;
                        }
                        Data AddItem = new Data();
                        AddItem.name = (idx++).ToString();
                        strlist.Add(AddItem);
                        Thread.Sleep(1);
                    }
                }
            }));
            th1.Start();

            Thread th2 = new Thread(new ThreadStart(() =>
            {
                strlist.Clear();
                for (int i = 0; i < 600; i++)
                {
                    if (idx == 65535)
                    {
                        idx = 0;
                    }
                    Data AddItem = new Data();
                    AddItem.name = (idx++).ToString();
                    strlist.Add(AddItem);
                    Thread.Sleep(1);
                }
            }));
            th2.Start();
        }
    }

    class Data
    {
        public string name {get; set;}
        public string aa{get; set;}
    }
}
